<template>
  <div class="main">
    <section>
      <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
        <el-form-item label="属性组名称:" prop="name" :rules="commonRules.notNullRule">
          <el-input :maxlength="32" v-model="form.name" placeholder="请输入属性组名称"></el-input>
        </el-form-item>

        <el-form-item label="属性组描述:" prop="description">
          <el-input type="textarea" :maxlength="125" :rows="5" placeholder="描述属性组特征,便于查找" v-model="form.description">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading" @click="submitForm('ruleForm')">保存</el-button>
        </el-form-item>
      </el-form>

    </section>
  </div>
</template>

<script>
import { insertAttrGroup, updataAttrGroup } from '@/api/goodMiddleStage'

export default {
  name: 'brand',
  data() {
    return {
      loading: false,
      form: {
        description: '',
        logo: '',
        name: ''
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      console.log(this.$route)
      this.form = this.$route.params
    },
    submitForm() {
      this.$refs['form'].validate(async valid => {
        if (valid) {
          try {
            this.loading = true
            let data = ''
            if (this.$route.name === 'goodsMiddleStage-propertyEdit') {
              data = await updataAttrGroup(this.form)
            } else {
              data = await insertAttrGroup(this.form)
            }
            if (data.message === 'SUCCESS') {
              this.loading = false
              this.$message.success('操作成功')
              this.$refs['form'].resetFields()
              this.$router.push({ path: '/goodsMiddleStage/property' })
            } else {
              this.$message.success('操作失败')
            }
          } catch (error) {
            console.log(error)
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
</style>